package com.corpgovernment.organization.controller;

import com.corpgovernment.api.organization.model.org.request.RegisterOrgRequest;
import com.corpgovernment.api.organization.model.org.request.ResisterOrgResponseVO;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.organization.service.IOrganizationInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户注册获取相关组织和公司信息
 *
 * @author jiexiangwang
 * @date 2019/9/26
 */
@RestController
@RequestMapping("register/org")
public class RegisterOrgController {
    @Autowired
    private IOrganizationInfoService organizationInfoService;

    /**
     * 根据公司关键字模糊搜索公司信息
     *
     * @param request 搜索请求
     * @return 公司结果
     */
    @PostMapping("search")
    public JSONResult<ResisterOrgResponseVO> getCorpsByKeyWord(@Validated(RegisterOrgRequest.CorpSearchValid.class) @RequestBody RegisterOrgRequest request) {
		return JSONResult.success(organizationInfoService.search(request));
    }

    /**
     * 根据公司关键字模糊搜索公司信息(新)
     *
     * @param request 搜索请求
     * @return 公司结果
     */
    @PostMapping("searchNew")
    public JSONResult<ResisterOrgResponseVO> getCorpsByKeyWordNew(@Validated(RegisterOrgRequest.CorpSearchValid.class) @RequestBody RegisterOrgRequest request) {
        return JSONResult.success(organizationInfoService.search(request));
    }

    /**
     * 根据公司id查询公司下的所有组织
     *
     * @param request 查询请求
     * @return 查询结果
     */
    @PostMapping("corps")
    public JSONResult getCorps(@Validated(RegisterOrgRequest.OrgSearchValid.class) @RequestBody RegisterOrgRequest request) {
        return organizationInfoService.corpSearch(request);
    }

    @GetMapping("query")
    public JSONResult<ResisterOrgResponseVO> queryAllCorps() {
		return JSONResult.success(organizationInfoService.search(null));
    }
}
